package com.company.woye.onpackage.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.company.woye.R;
import com.company.woye.onpackage.entity.OnPackageListEntity;
import com.company.woye.onpackage.entity.OnSonPackageListEntity;

import org.w3c.dom.Text;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class OnSonPackageListViewAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private List<OnSonPackageListEntity> listSonEntities;

    public OnSonPackageListViewAdapter(Context context, List<OnSonPackageListEntity> listEntities) {
        this.inflater = LayoutInflater.from(context);
        this.listSonEntities = listEntities;
    }

    @Override
    public int getCount() {
        return listSonEntities.size();
    }

    @Override
    public Object getItem(int position) {
        return listSonEntities.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHodler = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_adapter_on_son_package, parent, false);
            viewHodler = new ViewHolder(convertView);
            convertView.setTag(viewHodler);
        } else {
            viewHodler = (ViewHolder) convertView.getTag();
        }
//        viewHodler.tvHYH.setSelected(true);
//        viewHodler.tvHH.setSelected(true);
//        viewHodler.tvPO.setSelected(true);
//        viewHodler.tvDBH.setSelected(true);
//        viewHodler.tvLX.setSelected(true);

        viewHodler.tvYS.setSelected(true);
//        viewHodler.tvPSXX.setSelected(true);
//        viewHodler.tvCM.setSelected(true);
//        viewHodler.tvSH.setSelected(true);
//        viewHodler.tvSMBS.setSelected(true);
//
//        viewHodler.tvBS.setSelected(true);
//        viewHodler.tvBZ.setSelected(true);
//        viewHodler.tvKDY.setSelected(true);
        viewHodler.tvSC.setSelected(true);

        viewHodler.tvHYH.setText(listSonEntities.get(position).getStyleNo());
        viewHodler.tvHH.setText(listSonEntities.get(position).getOrderNo());
        viewHodler.tvPO.setText(listSonEntities.get(position).getPO());
        viewHodler.tvDBH.setText(listSonEntities.get(position).getDBH());
        viewHodler.tvLX.setText(listSonEntities.get(position).getStyleSort());

        viewHodler.tvYS.setText(listSonEntities.get(position).getColorName());
        viewHodler.tvPSXX.setText(listSonEntities.get(position).getPsxx());
        viewHodler.tvSH.setText(listSonEntities.get(position).getColorNo());
        viewHodler.tvCM.setText(listSonEntities.get(position).getSize());
        viewHodler.tvSMBS.setText(listSonEntities.get(position).getScanPackNum());

        viewHodler.tvBS.setText(listSonEntities.get(position).getPackNum());
        viewHodler.tvBZ.setText(listSonEntities.get(position).getMemo());
        viewHodler.tvKDY.setText(listSonEntities.get(position).getOperator());
        viewHodler.tvSC.setText(listSonEntities.get(position).getColor());


        return convertView;
    }


    static class ViewHolder {
        @BindView(R.id.tvHYH)
        TextView tvHYH;
        @BindView(R.id.tvHH)
        TextView tvHH;
        @BindView(R.id.tvPO)
        TextView tvPO;
        @BindView(R.id.tvDBH)
        TextView tvDBH;
        @BindView(R.id.tvLX)
        TextView tvLX;

        @BindView(R.id.tvYS)
        TextView tvYS;
        @BindView(R.id.tvPSXX)
        TextView tvPSXX;
        @BindView(R.id.tvSH)
        TextView tvSH;
        @BindView(R.id.tvCM)
        TextView tvCM;

        @BindView(R.id.tvSMBS)
        TextView tvSMBS;

        @BindView(R.id.tvBS)
        TextView tvBS;
        @BindView(R.id.tvBZ)
        TextView tvBZ;
        @BindView(R.id.tvKDY)
        TextView tvKDY;

        @BindView(R.id.tvSC)
        TextView tvSC;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
